package com.foreknow.service.impl;

import com.foreknow.bean.Admin;
import com.foreknow.dao.AdminDao;
import com.foreknow.dao.impl.AdminDaoImpl;
import com.foreknow.service.AdminService;

/**
 * Spring是面向接口来编程的。
 * IOC(控制反转):之前需要自己创建的对象现在可以交给Spring的IOC容器来创建。
 * 依赖注入(DI)
 */
public class AdminServiceImpl implements AdminService {

    private AdminDao adminDao; //注入接口

    public void setAdminDao(AdminDao adminDao) {
        this.adminDao = adminDao;
    }


    @Override
    public void add(Admin admin) {
        adminDao.save(admin);
    }

    public static void main(String[] args) {
        AdminServiceImpl service = new AdminServiceImpl();
        service.setAdminDao(new AdminDaoImpl()); //通过set方法初始化接口
        service.add(new Admin());
    }
}
